package com.itheima.spring.ioc;

import com.itheima.spring.model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class TestXMLSpringIOC {

    public static void main(String[] args) {

        //创建Spring上下文,加载bean.xml
        ApplicationContext context1 = new ClassPathXmlApplicationContext("spring-config.xml");

        //文件系统下加载xml配置文件创建bean定义
        ApplicationContext context2 = new FileSystemXmlApplicationContext("C:\\worker\\study\\study_code\\spring_project\\spring\\src\\main\\resources\\spring-config.xml");

        //通用的xml方式加载xml配置文件创建bean定义
        ApplicationContext context3 = new GenericXmlApplicationContext("file:C:\\worker\\study\\study_code\\spring_project\\spring\\src\\main\\resources\\spring-config.xml");

        //获取bean
        User user = context1.getBean("user", User.class);
        System.out.println(user.toString());
        //context3.close();
    }
}
